package mest.controller.hws;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import mest.entity.plan_purchase;
import mest.service.hws.Iplan_purchaseService;
import mest.service.system.DBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
* 计划采购单
* */
@RestController
@RequestMapping("/plan_purchase")
@CrossOrigin
public class plan_purchaseController {
    @Resource
    private Iplan_purchaseService pp;
    @Autowired
    private DBService dbService;

    //新增计划采购单
    @RequestMapping("/insert")
    public String insert(@RequestBody JSONObject json){
        System.out.println("进入方法");
        String theirDb = dbService.getDbName();
        Map<String,Object> record = json.toJavaObject(Map.class);
        record.put("theirDb",theirDb);
        return  pp.insert(record);
    }

    //更新计划采购单
    @RequestMapping("/updateByone")
    public String updateByPrimaryKey(plan_purchase record) {
        String theirDb = dbService.getDbName();
        return pp.updateByPrimaryKey(theirDb,record);
    }

    //根据id查询计划采购单
    @RequestMapping("/selectById")
    public String selectByPrimaryKey(Integer id, Integer finishStatus) {
        String theirDb = dbService.getDbName();
        return pp.selectByPrimaryKey(theirDb,id,finishStatus);
    }

    //查询所有计划采购单
    @RequestMapping("/selectAll")
    public Map<Object, Object> selectPrimary(Integer limit, Integer page, Integer finishStatus) {
        String theirDb = dbService.getDbName();
        return pp.selectPrimary(theirDb,limit,page,finishStatus);
    }
}
